package com.jp;

import com.jp.service.impl.MacGitLogPrint;
import com.jp.strategy.GitLogPrintStrategy;
import com.jp.utils.LogUtils;

import java.io.File;
import java.util.*;

public class Main {

    public static final String DATE_FORMAT = "yyyy-MM-dd";
    private static final String SYSTEM_SEPARATOR = File.separator;

    /**
     * today yesterday tw(this week) lw(last week) tm(this month) lm(last month) all
     */
    public static final Map<String, Integer> map = new HashMap<String, Integer>() {
        {
            this.put("today", 0);
            this.put("yesterday", 1);
            this.put("tw", 2);
            this.put("lw", 3);
            this.put("tm", 4);
            this.put("lm", 5);
            this.put("all", 6);
        }
    };

    public static void main(String[] args) throws Exception {
        // 获取用户输入
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入要查询的周期 today yesterday tw(this week) lw(last week) tm(this month) lm(last month) all");
        String next = scanner.next();

        // 判断输入是否在在规定的几种类型中
        if (map.containsKey(next)) {
            // 获得jar包的当前所在位置
            String filePath = LogUtils.getFilePath().replace("/CollectGitCommitMsg.jar", "");
            File file = new File(filePath);

            // 获得该路径下的所有文件
            for (File subFile : Objects.requireNonNull(file.listFiles())) {
                // 判断该文件是否为文件夹
                if (subFile.isDirectory()) {
                    String path = subFile.getPath();
                    String s = path + SYSTEM_SEPARATOR + ".git" + SYSTEM_SEPARATOR + "logs" + SYSTEM_SEPARATOR + "HEAD";
                    File file1 = new File(s);

                    // 判断文件是否存在
                    if (file1.exists()) {
                        System.out.println("\uD80C\uDD9C \uD80C\uDD9D \uD80C\uDD9E \uD80C\uDD9F \uD80C\uDDA1 \uD80C\uDD9C \uD80C\uDD9D \uD80C\uDD9E \uD80C\uDD9F 【" + subFile.getName() + "】 \uD80C\uDD9C \uD80C\uDD9D \uD80C\uDD9E \uD80C\uDD9F \uD80C\uDDA1 \uD80C\uDD9C \uD80C\uDD9D \uD80C\uDD9E \uD80C\uDD9F");
                        new GitLogPrintStrategy(new MacGitLogPrint()).executeStrategy(s, next);
                    }
                }
            }
        } else {
            System.out.println("输入错误");
        }

    }
}